{
Author:  Prof1983 prof1983@yandex.ru
Created: 22.10.2008
LastMod: 19.03.2009
}
unit ModuleManagerImpl;

interface

uses
  ABase, ABaseIntf, AUI, AUIcl, ModuleManagerWin;

const
  ModuleManagerGuid: TGuid = '{9FECAE5B-3904-41B6-B5E5-D143C6979EC7}';

type
  TModuleManager = class(TInterfacedObject, IAModule)
  private
    FCore: IACore;
    FInitialized: Boolean;
    FUserInterface: IAUIcl;
    ModuleManagerWin: TModuleManagerWindow;
    procedure ModuleManagerClick(Event, Params: Integer);
  protected
    function GetGuid: TGuid;
    function GetInfo: AString;
    function GetIsInitialized: ABoolean;
    function GetName: AString;
  public
    procedure Done;
    function Init(Core: IACore): AInteger;
  public
    constructor Create;
  end;

implementation

var
  Module: TModuleManager;

{ TModuleManager }

constructor TModuleManager.Create;
begin
  inherited;
  Module := Self;
end;

procedure TModuleManager.Done;
begin
  if Assigned(ModuleManagerWin) then
  begin
    ModuleManagerWin.Free();
    ModuleManagerWin := nil;
  end;
  FCore := nil;
  FUserInterface := nil;
  FInitialized := False;
end;

function TModuleManager.GetGuid: TGuid;
begin
  Result := ModuleManagerGuid;
end;

function TModuleManager.GetInfo: AString;
begin
  Result := '';
end;

function TModuleManager.GetIsInitialized: ABoolean;
begin
  Result := FInitialized;
end;

function TModuleManager.GetName: AString;
begin
  Result := 'ModuleManager';
end;

function TModuleManager.Init(Core: IACore): AInteger;
var
  miTools: IAUIMenuItem;
begin
  if FInitialized then
  begin
    Result := 0;
    Exit;
  end;

  FCore := Core;
  FUserInterface := IAUIcl(FCore.GetModuleByGuid(AUIGuid));
  if Assigned(FUserInterface) then
  begin
    FUserInterface.Init(FCore);
    miTools := FUserInterface.MainWindow.Menu.Items.GetItemByNameA('Tools', 'Tools', 900);
    miTools.Add('ModuleManager', 'Module Manager', ModuleManagerClick, 0, 0);
  end;
  FInitialized := True;
  Result := 0;
end;

procedure TModuleManager.ModuleManagerClick(Event, Params: Integer);
begin
  if not(Assigned(ModuleManagerWin)) then
    ModuleManagerWin := TModuleManagerWindow.Create(FUserInterface);
  ModuleManagerWin.Show();
end;

end.
 
